/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2017-07-21 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.h5.controller.ware;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.domain.po.WareCatBrandPo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.generic.connector.IWareCatBrandConnector;
import com.itttq.gshop.generic.controller.GenericController;

@RestController
@RequestMapping("wareCatBrand")
public class WareCatBrandController extends GenericController {
	private static final long serialVersionUID = -1985776541571428L;
	public static final String cacheKey = "wareCatBrand";
	@Autowired
	private IWareCatBrandConnector wareCatBrandConnector;

	@RequestMapping("categories.html")
    public ModelAndView getCategoryAndBrand() {
		ModelAndView mv = new ModelAndView("/product/category");
		mv.addObject("catBrandMap", wareCatBrandConnector.getAllEnableCatBrands());
        return mv;
    }
	
	@RequestMapping("list")
    public ResultPageTo<WareCatBrandPo> getWareCatBrands(WareCatBrandPo wareCatBrand) {
        return wareCatBrandConnector.getWareCatBrands(wareCatBrand);
    }
	
	@RequestMapping("/{id:^[0-9]*$}")
	@Cacheable(value=cacheKey, key="'wareCatBrand_'+#id")
	public WareCatBrandPo getWareCatBrand(@PathVariable("id") int id) {
		return wareCatBrandConnector.getWareCatBrand(id);
	}

	@RequestMapping("/save")
	@CacheEvict(value=cacheKey, key="'wareCatBrand_'+#wareCatBrand.id")
	public Integer saveWareCatBrand(WareCatBrandPo wareCatBrand) {
		return wareCatBrandConnector.saveWareCatBrand(wareCatBrand);
	}

	@RequestMapping("/del/{id:^[0-9]*$}")
	@CacheEvict(value=cacheKey, key="'wareCatBrand_'+#id")
	public Integer delWareCatBrand(@PathVariable("id") int id) {
		return wareCatBrandConnector.delWareCatBrand(id);
	}
}